/*
 *  By Luocheng Tang
*/

package com.lvmama.vst.batis.dsobject;

import java.util.HashMap;
import java.util.Map;

public abstract class DsObjectParent implements DsObject {
	protected String url;
	protected String username; 
	protected String password;

	protected int maxActive;
	protected int initialSize;
	protected int maxWait;
	protected int minIdle;

	protected String driverClassName;
	protected boolean testWhileIdle;
	protected int timeBetweenEvictionRunsMillis;
	protected int minEvictableIdleTimeMillis;
	protected String validationQuery;
	protected boolean removeAbandoned;
	protected int removeAbandonedTimeout;

	protected boolean testOnBorrow;
	protected boolean testOnReturn;

	protected Map<String, Object> configedFields;
	
	public DsObjectParent() {
		configedFields = new HashMap<>(); 
	}
	
	public abstract String getObjectPrefix();

	@Override
	public Map<String, Object> getConfigedFields() {
		return configedFields;
	}

	public void setUrl(String url) { 
		configedFields.put("setUrl", url);
		this.url = url;
	}

	public void setUsername(String username) {
		configedFields.put("setUsername", username);
		this.username = username;
	}

	public void setPassword(String password) {
		configedFields.put("setPassword", password);
		this.password = password;
	}

	public void setMaxActive(int maxActive) {
		configedFields.put("setMaxActive", maxActive);
		this.maxActive = maxActive;
	}

	public void setInitialSize(int initialSize) {
		configedFields.put("setInitialSize", initialSize);
		this.initialSize = initialSize;
	}

	public void setMaxWait(int maxWait) {
		configedFields.put("setMaxWait", maxWait);
		this.maxWait = maxWait;
	}

	public void setMinIdle(int minIdle) {
		configedFields.put("setMinIdle", minIdle);
		this.minIdle = minIdle;
	}

	public void setDriverClassName(String driverClassName) {
		configedFields.put("setDriverClassName", driverClassName);
		this.driverClassName = driverClassName;
	}

	public void setTestWhileIdle(boolean testWhileIdle) {
		configedFields.put("setTestWhileIdle", testWhileIdle);
		this.testWhileIdle = testWhileIdle;
	}

	public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
		configedFields.put("setTimeBetweenEvictionRunsMillis", timeBetweenEvictionRunsMillis);
		this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
	}

	public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
		configedFields.put("setMinEvictableIdleTimeMillis", minEvictableIdleTimeMillis);
		this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
	}

	public void setValidationQuery(String validationQuery) {
		configedFields.put("setValidationQuery", validationQuery);
		this.validationQuery = validationQuery;
	}

	public void setRemoveAbandoned(boolean removeAbandoned) {
		configedFields.put("setRemoveAbandoned", removeAbandoned);
		this.removeAbandoned = removeAbandoned;
	}

	public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
		configedFields.put("setRemoveAbandonedTimeout", removeAbandonedTimeout);
		this.removeAbandonedTimeout = removeAbandonedTimeout;
	}

	public void setTestOnBorrow(boolean testOnBorrow) {
		configedFields.put("setTestOnBorrow", testOnBorrow);
		this.testOnBorrow = testOnBorrow;
	}

	public void setTestOnReturn(boolean testOnReturn) {
		configedFields.put("setTestOnReturn", testOnReturn);
		this.testOnReturn = testOnReturn;
	}

	@Override
	public String toString() {
		return getObjectPrefix() + ": [configedFields=" + configedFields + "]";
	}
}
